package com.liudadan.controller;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.http.HttpResponse;

@Controller
@RequestMapping("/cookie")
@ResponseBody
public class CookieController {
    @GetMapping("/save")
    public String saveCookie(HttpServletResponse response){
        Cookie cookie = new Cookie("name","root");
        response.addCookie(cookie);
        return "success";
    }

    @GetMapping("/get")
    public String getCookie(@CookieValue(name = "name") String name){
        System.out.println("CookieController.show");
        System.out.println("name" + name);
        return name;
    }
}
